#include('../header.html', {title: '我的评价'})

<div id="content-container" class="container">
  <div class="row row-3-9 my-layout">
    <div class="col-md-3">
      #include('sideMenu.html', {user: '', name: '我的评价'})
    </div>

    <div id="vue-comment" class="col-md-9">
      <div class="panel panel-default panel-col">
        <div class="panel-heading">我的评价</div>
        <div class="panel-body">
          <div v-if="comments.length==0" class="empty">还没有写过任何评价</div>

          <div v-if="comments.length>0" v-for="(comment,index) in comments">
            <div class="media media-evaluate">
              <div class="media-body thread-post">
                <div class="title">
                  <a :href="'/course/'+comment.course.id+'/join/info'">{{comment.course.name}}</a>
                  <time class="pull-right">{{comment.time}}</time>
                </div>
                <div class="clearfix">
                  <div class="score">
                    <i v-for="i in 5" :class="'es-icon es-icon-star '+ (comment.star>=i?'color-warning':'color-grey')"></i>
                  </div>
                  <a href="javascript:" class="pull-right notebook-note-delete" title="删除评价" @click="deleteById(comment.id,index)">
                    <span class="glyphicon glyphicon-trash"></span>
                  </a>
                </div>
                <div class="content">
                  <div class="short-content">
                    {{comment.content}}
                  </div>
                </div>
              </div>
            </div>
          </div>

        </div>
      </div>
      <nav v-if="page.totalPages>1" class="text-center">
        <navigation :pages="page.totalPages" :current.sync="page.pageNum" @navpage="gotoPage"/>
      </nav>
    </div>
  </div>
</div>

<script type="text/javascript">
    var vm = new Vue({
        el: '#vue-comment',
        data: {
            empty: false,
            comments: [],
            page:{
                pageNum:1,
                totalPages:1,
                limit:8,
                totalRows:1
            }

        },
        watch:{
          'page.pageNum':function () {
              this.showMyComments();
          }
        },
        methods: {
            gotoPage:function (page) {
                this.page.pageNum = page;
            },

            showMyComments: function () {
                var self = this;
                $.post('/comment/pages', {uid:${user.id},page:self.page.pageNum}, function (data) {
                        if (data.success){
                            self.comments=[];
                            self.comments = data.payload.rows;
                            self.page.pageNum=data.payload.pageNum;
                            self.page.totalPages=data.payload.totalPages;
                            self.page.totalRows=data.payload.totalRows;
                        }
                })
            },

            deleteById: function (id,index) {
                var self = this;
                $.post("/comment/deleteById",{id: id}, function (data) {
                    if (data.success) {
                        self.comments.splice(index, 1);
                        layer.msg('删除成功！', {
                            time: 1500
                        });
                    }

                })
            }
        },
        created:function () {
            this.showMyComments();
        }
    })
</script>
#include('../footer.html')